package com.secondGroup.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.secondGroup.entity.BankCard;
import com.secondGroup.entity.VirtualBankCard;
import com.secondGroup.mapper.BankCardMapper;
import com.secondGroup.mapper.VirtualBankCardMapper;
import com.secondGroup.service.BankCardService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ybk
 * @since 2022-05-05
 */
@Service
public class BankCardServiceImpl extends ServiceImpl<BankCardMapper, BankCard> implements BankCardService {
    @Resource
    private BankCardMapper bankCardMapper;

    @Autowired
    private VirtualBankCardMapper virtualBankCardMapper;

    @Override
    public void insert(String account, String cid) {
        bankCardMapper.insert(account,cid);
    }

    @Override
    public BankCard find(String cid) {
        return bankCardMapper.find(cid);
    }

    @Override
    public Boolean ifBindingCard(String account) {
        QueryWrapper<BankCard> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account", account);
        Long aLong = bankCardMapper.selectCount(queryWrapper);
        if (aLong == 0){
            return true;
        }
        return false;
    }
    @Override
    public List<VirtualBankCard> queryBankCard(String account) {
        List<BankCard> list = bankCardMapper.queryBankCard(account);
        List<VirtualBankCard> virtualBankCardList = new ArrayList<>();
        for (BankCard bankCard:list) {
            VirtualBankCard virtualBankCard = virtualBankCardMapper.selectVirtualBank(bankCard.getCId());
            virtualBankCardList.add(virtualBankCard);
        }
        return virtualBankCardList;
    }
}
